#include<iostream>
using namespace std;
struct card
{
	char suit;
	int n;
};
int main()
{	
	int	N;
	cin>>N;
	int i,j,k,m;
	struct card A[N];
	for(i=0;i<N;i++)
	{
		cin>>A[i].n;
		cin>>A[i].suit;
	}
/*	for(k=0;k<N-1;k++)
	{
		for(m=N;m>0;m--)
		{
			if(A[m].n<A[m-1].n)
			{ 
				swap(A[m].n,A[m-1].n);
				swap(A[m].suit,A[m-1].suit);
			} 
		}
	}
*/
	for(int s=0;s<N;s++)
	{
		cout<<A[s].n<<A[s].suit<<endl;
	}
	return 0;
}

